#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../statfiles/conf.h"


int gen_files (const char *fil_pth, char *name) {
    unsigned char *conf;
    size_t conf_len;
    printf("name is %s\n", name);

    if (strcmp(name, "redis") == 0) {
        printf("String is redis\n");
//        conf = redis_conf;
//        conf_len = redis_conf_len;
    }
    else if (strcmp(name, "minio") == 0) {
        printf("String is minio\n");
//        conf = minio_conf;
//        conf_len = minio_conf_len;
    }
    else if (strcmp(name, "nacos") == 0) {
        printf("String is nacos\n");
    }
    else if (strcmp(name, "all") == 0) {
        printf("String is all\n");
        conf = conf_tgz;
        conf_len = conf_tgz_len;
    }
    else {
        printf("String is unknown\n");
    }
    // 打开新文件，准备写入
    FILE *file = fopen(fil_pth, "wb");
    if (!file) {
        perror("Error opening file for writing");
        return 1;
    }

    // 写入文件内容
    size_t written = fwrite(conf, 1, conf_len, file);
    if (written != conf_len) {
        perror("Error writing to file");
        fclose(file);
        return 1;
    }

    // 关闭文件
    fclose(file);
    return 0;

}
